package football.core;

import playn.core.PlayN;
import playn.core.Sound;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by tol on 21.05.2014.
 */
public class CoreSound implements ISound {
    Map<String, Sound> sounds=new HashMap<String,Sound>();

    private Sound get(String name){
        name="sounds/"+name;
        Sound sound=sounds.get(name);
        if(sound==null){
            sound = PlayN.assets().getSound(name);
            sounds.put(name,sound);
        }
        return sound;
    }

    @Override
    public void play(String name) {
        get(name).play();
    }

    @Override
    public void loop(String name) {
        Sound sound=get(name);
        sound.setLooping(true);
        sound.play();
    }

    @Override
    public void stop(String name) {
        get(name).stop();
    }

    @Override
    public void volume(String name, float volume) {
        Sound sound=get(name);
        sound.setVolume(volume);
    }
}
